Skip to content

refactor: centralize env access via internal/env package - #27

Merged
Patel230 merged 4 commits into
mainfrom
chore/centralize-env-access
Jun 12, 2026
Merged

refactor: centralize env access via internal/env package#27
Patel230 merged 4 commits into
mainfrom
chore/centralize-env-access

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

Summary

  • Create internal/env/env.go with zero-dependency Getenv wrapper importable by all internal/ packages without cycle risk
  • config.Getenv now delegates to env.Getenv to avoid forcing all callers through the heavyweight internal/config package
  • Migrate os.Getenv calls across internal/ to use env.Getenv or config.Getenv (whichever is cycle-safe)
  • Update AGENTS.md policy: env.Getenv for simple reads, config.EnvManager for profile/secret management
  • Add explicit exceptions for runtime probes (TMUX, STY, TERM_PROGRAM, SHELL, GOPATH, HOME) and telemetry env vars

Files Changed

  • New: internal/env/env.go — zero-dependency wrapper around os.Getenv
  • Updated: internal/config/envmanager.goconfig.Getenv delegates to env.Getenv
  • Updated: internal/autoinit/autoinit.goos.Getenvconfig.Getenv
  • Updated: internal/auth/auth.goos.Getenv("HOME") → portable homeDir() helper
  • Updated: internal/tool/safety.goos.Getenv("HAWK_CONFIG_DIR")env.Getenv
  • Updated: internal/tool/web_search_brave.goos.Getenv("BRAVE_SEARCH_API_KEY")env.Getenv
  • Updated: internal/tool/web_search_searxng.goos.Getenv("SEARXNG_URL")env.Getenv
  • Updated: internal/resilience/health/diagnostics.goos.Getenv("HAWK_MODEL")config.Getenv
  • Updated: AGENTS.md — anti-pattern updated to reflect env.Getenv and document exceptions

Why a separate internal/env package?

internal/config imports internal/tool, which means internal/tool cannot import internal/config without creating a cycle. A tiny internal/env package with zero hawk-internal dependencies resolves this.

Verification

  • go build ./...
  • go vet ./...
  • go test ./internal/{env,autoinit,auth,tool,resilience/health}/
  • The pre-existing TestFormatDeveloperPathReport_ContainsSections flake (macOS keychain prompt) is unrelated to these changes

Patel230 added 4 commits June 12, 2026 12:16
… CI/CD

- Replace all context.TODO() calls in production and test code
  with context.Background() or proper context propagation
- Enable shadow and nilness govet linters; re-enable select
  staticcheck checks (SA4006, S1011, S1034)
- Fix CI coverage threshold comment (50% -> 60%)
- Extract markdownlint config to .markdownlint-cli2.jsonc
- Pin actions/setup-go to SHA in setup-deps and hawk actions
- Change setup-deps default branch from dev to main
- Add tracking issue references to all t.Skip() calls
- Create internal/env/env.go with zero-dependency Getenv wrapper
- Update config.Getenv to delegate to env.Getenv
- Migrate os.Getenv calls across internal/ to env.Getenv or config.Getenv
- Update AGENTS.md policy: env.Getenv for simple reads,
  config.EnvManager for profile/secret management
- Add exceptions for runtime probes and telemetry
This commit resolves all 145 golangci-lint issues that surfaced when the
shadow, nilness, and additional staticcheck checks were enabled:

- 142 shadow (govet): renamed inner shadowed variables to context-specific
  names (statErr, writeErr, unmarshalErr, etc.)
- 22 model/provider shadows: renamed to modelName/providerName
- 2 nilness tautologies (non-nil != nil): removed redundant nil checks
- 1 staticcheck SA4006 (unused value): removed dead assignment

No function signatures, exported types, or behavior changed. No linters
were disabled or skipped. .golangci.yml is unchanged.

Build and lint pass cleanly. The CI lint check on PR #26 will now pass.
@Patel230
Patel230 merged commit f68249c into main Jun 12, 2026
18 checks passed
@Patel230
Patel230 deleted the chore/centralize-env-access branch June 12, 2026 10:34
Patel230 added a commit that referenced this pull request Jun 15, 2026
* refactor: replace context.TODO() with context.Background() and harden CI/CD

- Replace all context.TODO() calls in production and test code
  with context.Background() or proper context propagation
- Enable shadow and nilness govet linters; re-enable select
  staticcheck checks (SA4006, S1011, S1034)
- Fix CI coverage threshold comment (50% -> 60%)
- Extract markdownlint config to .markdownlint-cli2.jsonc
- Pin actions/setup-go to SHA in setup-deps and hawk actions
- Change setup-deps default branch from dev to main
- Add tracking issue references to all t.Skip() calls

* refactor: centralize env access via internal/env package

- Create internal/env/env.go with zero-dependency Getenv wrapper
- Update config.Getenv to delegate to env.Getenv
- Migrate os.Getenv calls across internal/ to env.Getenv or config.Getenv
- Update AGENTS.md policy: env.Getenv for simple reads,
  config.EnvManager for profile/secret management
- Add exceptions for runtime probes and telemetry

* fix: resolve 145 golangci-lint shadow and nilness issues

This commit resolves all 145 golangci-lint issues that surfaced when the
shadow, nilness, and additional staticcheck checks were enabled:

- 142 shadow (govet): renamed inner shadowed variables to context-specific
  names (statErr, writeErr, unmarshalErr, etc.)
- 22 model/provider shadows: renamed to modelName/providerName
- 2 nilness tautologies (non-nil != nil): removed redundant nil checks
- 1 staticcheck SA4006 (unused value): removed dead assignment

No function signatures, exported types, or behavior changed. No linters
were disabled or skipped. .golangci.yml is unchanged.

Build and lint pass cleanly. The CI lint check on PR #26 will now pass.
Patel230 added a commit that referenced this pull request Jun 18, 2026
* refactor: replace context.TODO() with context.Background() and harden CI/CD

- Replace all context.TODO() calls in production and test code
  with context.Background() or proper context propagation
- Enable shadow and nilness govet linters; re-enable select
  staticcheck checks (SA4006, S1011, S1034)
- Fix CI coverage threshold comment (50% -> 60%)
- Extract markdownlint config to .markdownlint-cli2.jsonc
- Pin actions/setup-go to SHA in setup-deps and hawk actions
- Change setup-deps default branch from dev to main
- Add tracking issue references to all t.Skip() calls

* refactor: centralize env access via internal/env package

- Create internal/env/env.go with zero-dependency Getenv wrapper
- Update config.Getenv to delegate to env.Getenv
- Migrate os.Getenv calls across internal/ to env.Getenv or config.Getenv
- Update AGENTS.md policy: env.Getenv for simple reads,
  config.EnvManager for profile/secret management
- Add exceptions for runtime probes and telemetry

* fix: resolve 145 golangci-lint shadow and nilness issues

This commit resolves all 145 golangci-lint issues that surfaced when the
shadow, nilness, and additional staticcheck checks were enabled:

- 142 shadow (govet): renamed inner shadowed variables to context-specific
  names (statErr, writeErr, unmarshalErr, etc.)
- 22 model/provider shadows: renamed to modelName/providerName
- 2 nilness tautologies (non-nil != nil): removed redundant nil checks
- 1 staticcheck SA4006 (unused value): removed dead assignment

No function signatures, exported types, or behavior changed. No linters
were disabled or skipped. .golangci.yml is unchanged.

Build and lint pass cleanly. The CI lint check on PR #26 will now pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant